package diamond.day05;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) {
        NumThread numThread = new NumThread();
        FutureTask futureTask = new FutureTask(numThread);
        Thread thread = new Thread(futureTask);
        thread.start();
        try {
            //get()方法返回值即是FutureTask构造器参数Callable实现类的call方法的返回值
            Object o = futureTask.get();
            System.out.println(o);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
}

class NumThread implements Callable{

    public Object call() throws Exception {
        int sum = 0;
        for(int i =1;i<=100;i++){
            if(i%2==0){
                System.out.println(i);
                sum += i;
            }
        }
        return sum;
    }
}

class NumThread1 implements Runnable{
    public void run() {
        for(int i =1;i<=100;i++){
            if(i%2==0){
                System.out.println(i);
            }
        }
    }
}
